package com.crm.config.security.handler;

import com.crm.commons.domain.ResponseData;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class MyAuthenticationFailureHandler implements AccessDeniedHandler {



    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        //创建结果对象
        ResponseData responseData = new ResponseData(-1,"您没有权限访问该资源！！");
        //返回响应
        response.setContentType("application/json;charset=UTF-8");
        response.getWriter().println(responseData);
    }
}